interface User {
  name: string;
  age: number;
  sayHello: () => void;
}

/* type User = {
  name: string;
  age: number;
  sayHello(): void
}; */

let user: User = {
  name: "zs",
  age: 12,
  sayHello() {
    console.log("sayHello");
  },
};

// 接口和别名如何约束函数
// type Condition = (n: number) => boolean;
/* type Condition = {
  (n: number): boolean
} */
interface Condition {
  (n: number): boolean;
}

function sum(numbers: number[], cb: Condition) {
  return numbers.reduce((pre, cur) => {
    if (cb(cur)) {
      pre += cur;
      return pre;
    }
  }, 0);
}

// 接口继承
interface A {
  T1: string;
}

interface B {
  T2: number;
}

interface C extends A, B {
  // T1: number;    // 接口不能重新覆盖父接口的成员
  T3: number;
}

/* type A = {
  T1: string;
};
type B = {
  T2: number;
};
type C = {
  T3: number;
  T1: number; // 交叉类型会将相同属性的类型变为never类型
} & A &
  B; */

let u: C = {
  T1: "t1",
  T2: 2,
  T3: 3,
};
